//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //1.BM1字符串变形
        public String trans (String s, int n) {
            if (n == 0) {
                return s;
            }
            StringBuffer str = new StringBuffer();
            //遍历字符串遇到大写就转化为小写，遇到小写就转化为大写
            for (int i = 0; i < n; i++) {
                char ch = s.charAt(i);
                if (s.charAt(i) <= 'Z' && s.charAt(i) >= 'A') {
                    str.append(Character.toLowerCase(ch));
                }
                if (s.charAt(i) <= 'z' && s.charAt(i) >= 'a') {
                    str.append(Character.toUpperCase(ch));
                }
                if (s.charAt(i) == ' ') {
                    str.append(ch);
                }
            }
            //将字符串str全部翻转
            str.reverse();
            //将单个单词进行翻转，以空格为界限
            for (int i = 0; i < n; i++) {
                int j = i;
                while (j < n && str.charAt(j) != ' ')
                    j++;
                //提取i到j的子字符串
                String tmp = str.substring(i, j);
                //使用 StringBuffer 构造子字符串 temp
                StringBuffer buff = new StringBuffer(tmp);
                //将buff这个子字符串翻转
                tmp = buff.reverse().toString();
                //将tmp替换原字符串i到j的子字符串
                str.replace(i, j, tmp);
                i = j;
            }
            return str.toString();
        }
        //2.BM1斐波那契数列
        public int Fibonacci (int n) {
            if(n == 1 || n==2) {
                return 1;
            }
            return Fibonacci(n-1) + Fibonacci(n-2);
        }
        //3.BM14判断是否平衡二叉树
        public boolean IsBalanced_Solution (TreeNode pRoot) {
            if(pRoot == null) {
                return true;
            }
            return IsBalanced_Solution_Child(pRoot) >= 0;
        }
        public int IsBalanced_Solution_Child(TreeNode root) {
            if(root == null) {
                return 0;
            }
            int leftTree = IsBalanced_Solution_Child(root.left);
            int rightTree = IsBalanced_Solution_Child(root.right);
            if(leftTree >= 0 && rightTree >= 0 && Math.abs(leftTree - rightTree) <=1) {
                return Math.max(leftTree,rightTree) + 1;
            } else {
                return -1;
            }
        }
    }
    }
}